/**
 * Object.fromEntries
 * - 依据entries获取对象
 */
const obj = {
  name: 'li',
  age: 10
}
const arr = Object.entries(obj)
console.log(arr) //[ [ 'name', 'li' ], [ 'age', 10 ] ]
const obj1 = Object.fromEntries(arr)
console.log(obj1)
console.log(obj1 === obj) //false

/**
 * 应用场景
 * 将url中的query转换为对象
 */
const queryStr = 'name=jack&age=18&height=1.9'
const queryParams = new URLSearchParams(queryStr)
const paramObj = Object.fromEntries(queryParams)
//{ name: 'jack', age: '18', height: '1.9' }
console.log(paramObj)

//queryParams就是一个可当做entries的结构
//URLSearchParams { 'name' => 'jack', 'age' => '18', 'height' => '1.9' }
console.log(queryParams)
for (const param of queryParams) {
  console.log(param)
}
//[ 'name', 'jack' ]
// [ 'age', '18' ]
// [ 'height', '1.9' ]



